<template>
  <zh-form-card title="基本信息" :span="24">
    <zh-form ref="formRef" :model="data.formData" label-width="200px" :span="12" :rules="data.rules">
            <zh-form-input
          prop="retCode"
          label="交易结果状态"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.retCode"
      ></zh-form-input>
      <zh-form-input
          prop="message"
          label="交易结果 信息"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.message"
      ></zh-form-input>
      <zh-form-input
          prop="interfaceCode"
          label="接口编号"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.interfaceCode"
      ></zh-form-input>
      <zh-form-input
          prop="title"
          label="接口名称"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.title"
      ></zh-form-input>
      <zh-form-date
          prop="reqTime"
          label="请求时间"
          type="datetime"
          :disabled="props.disabled"
          v-model="data.formData.reqTime"
          :span="8"
      ></zh-form-date>
      <zh-form-date
          prop="resTime"
          label="返回时间"
          type="datetime"
          :disabled="props.disabled"
          v-model="data.formData.resTime"
          :span="8"
      ></zh-form-date>
      <zh-form-input
          prop="takingTime"
          label="总耗时 单位秒"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.takingTime"
      ></zh-form-input>
      <zh-form-input
          prop="convertReqTime"
          label="接口调用转换耗时 单位秒"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.convertReqTime"
      ></zh-form-input>
      <zh-form-input
          prop="convertResTime"
          label="接口返回转换耗时 单位秒"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.convertResTime"
      ></zh-form-input>
      <zh-form-input
          prop="producerTakingTime"
          label="调用第三方服务耗时  单位秒"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.producerTakingTime"
      ></zh-form-input>
      <zh-form-input
          prop="consumerAppId"
          label="调用方 应用"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.consumerAppId"
      ></zh-form-input>
      <zh-form-input
          prop="consumerAppName"
          label="调用方 应用系统名称"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.consumerAppName"
      ></zh-form-input>
      <zh-form-input
          prop="consumerId"
          label="消费者主键"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.consumerId"
      ></zh-form-input>
      <zh-form-input
          prop="producerAppId"
          label="所属应用 服务方"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.producerAppId"
      ></zh-form-input>
      <zh-form-input
          prop="producerAppName"
          label="应用系统名称 服务方"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.producerAppName"
      ></zh-form-input>
      <zh-form-input
          prop="producerPath"
          label="转发地址"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.producerPath"
      ></zh-form-input>
      <zh-form-input
          prop="ym"
          label="年月"
          type="number"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.ym"
      ></zh-form-input>
      <zh-form-input
          prop="reqIp"
          label="请求ip"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.reqIp"
      ></zh-form-input>
      <zh-form-input
          prop="areaCode"
          label="行政区划"
          :disabled="props.disabled"
          :span="8"
          v-model="data.formData.areaCode"
      ></zh-form-input>
      <zh-form-input
          prop="reqBody"
          label="请求报文"
          :disabled="props.disabled"
          type="textarea"
          :span="24"
          v-model="data.formData.reqBody"
      ></zh-form-input>
      <zh-form-input
          prop="resBody"
          label="返回报文"
          type="textarea"
          :disabled="props.disabled"
          :span="24"
          v-model="data.formData.resBody"
      ></zh-form-input>
      <zh-form-input
          prop="reqConvertBody"
          label="请求报文(转换后)"
          type="textarea"
          :disabled="props.disabled"
          :span="24"
          v-model="data.formData.reqConvertBody"
      ></zh-form-input>
      <zh-form-input
          prop="resConvertBody"
          label="返回报文(转换后)"
          type="textarea"
          :disabled="props.disabled"
          :span="24"
          v-model="data.formData.resConvertBody"
      ></zh-form-input>
    </zh-form>
  </zh-form-card>
</template>

<script lang="ts" setup name="apiLogForm">
import { ElMessage } from 'element-plus';

//------------------定义子组件---------------------------
const formRef = ref();
//------------------接收传入参数(组件)-------------------
const props = defineProps({
  logId: {
    type: String,
    default: '',
  },
  disabled: {
    type: Boolean,
    default: true,
  },
  btnLoding: Boolean,
});
const emits = defineEmits(['update:btnLoding', 'canner', 'refreshTable']);
//------------------初始化------------------------------
onMounted(() => {
  getDict();
  getsurveyInfo();
});
//------------------内部变量定义-------------------------
const data = reactive({
  formData: {} as any,
  detailVisible: true,
  loading: false,
  rules: {
  },
  dictData: {} as any,
  areaCodeDict: [] as any,
  campusParam: {} as any,
});

// 查询数据字典信息
const getDict = () => {
  const params = {} as any;
  params.dictFields = '';
  $api.common.getBatchDict.post(params).then((res) => {
    data.dictData = res.result;
  });
};

//获取详情
const getsurveyInfo = () => {
  if (!props.logId) {
    return;
  }
  data.loading = true;
  $api.common.send
  .post('APILOG0002', { logId: props.logId })
  .then((res: any) => {
    data.formData = res.result || {};
    data.loading = false;
    data.campusParam.schoolId = data.formData.schoolId;
  })
  .catch(() => {
    data.loading = false;
  });
};

//保存
async function saveBase() {
  let checkFlag = await formRef.value.checkForm();
  if (checkFlag) {
    if (data.formData.logId) {
      $api.common.send
      .post('APILOG0005', data.formData)
      .then(() => {
        ElMessage.success('修改成功');
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = false));
        emits('refreshTable');
      })
      .catch(() => {
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = true));
      });
    } else {
      $api.common.send
      .post('APILOG0004', data.formData)
      .then(() => {
        ElMessage.success('新增成功');
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = false));
        emits('refreshTable');
      })
      .catch(() => {
        emits('update:btnLoding', false);
        emits('canner', (data.detailVisible = true));
      });
    }
  }
}

//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({ saveBase });
</script>
<style lang="scss" scoped></style>
